package com.ruoyi.pms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.pms.domain.PmsAttrKey;
import com.ruoyi.pms.service.IPmsAttrKeyService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商品属性名Controller
 * 
 * @author yf
 * @date 2022-02-13
 */
@RestController
@RequestMapping("/key")
public class PmsAttrKeyController extends BaseController
{
    @Autowired
    private IPmsAttrKeyService pmsAttrKeyService;

    /**
     * 无分页的查询商品属性名列表
     */
    @RequiresPermissions("pms:key:list")
    @GetMapping("/getlist")
    public AjaxResult getlist(PmsAttrKey pmsAttrKey)
    {

        List<PmsAttrKey> list = pmsAttrKeyService.selectPmsAttrKeyList(pmsAttrKey);
        AjaxResult ajax = AjaxResult.success();
        ajax.put("attrlist",list);

        return ajax;
    }
    /**
     * 查询商品属性名列表
     */
    @RequiresPermissions("pms:key:list")
    @GetMapping("/list")
    public TableDataInfo list(PmsAttrKey pmsAttrKey)
    {
        startPage();
        List<PmsAttrKey> list = pmsAttrKeyService.selectPmsAttrKeyList(pmsAttrKey);
        return getDataTable(list);
    }

    /**
     * 导出商品属性名列表
     */
    @RequiresPermissions("pms:key:export")
    @Log(title = "商品属性名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsAttrKey pmsAttrKey)
    {
        List<PmsAttrKey> list = pmsAttrKeyService.selectPmsAttrKeyList(pmsAttrKey);
        ExcelUtil<PmsAttrKey> util = new ExcelUtil<PmsAttrKey>(PmsAttrKey.class);
        util.exportExcel(response, list, "商品属性名数据");
    }

    /**
     * 获取商品属性名详细信息
     */
    @RequiresPermissions("pms:key:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pmsAttrKeyService.selectPmsAttrKeyById(id));
    }

    /**
     * 新增商品属性名
     */
    @RequiresPermissions("pms:key:add")
    @Log(title = "商品属性名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsAttrKey pmsAttrKey)
    {
        return toAjax(pmsAttrKeyService.insertPmsAttrKey(pmsAttrKey));
    }

    /**
     * 修改商品属性名
     */
    @RequiresPermissions("pms:key:edit")
    @Log(title = "商品属性名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsAttrKey pmsAttrKey)
    {
        return toAjax(pmsAttrKeyService.updatePmsAttrKey(pmsAttrKey));
    }

    /**
     * 删除商品属性名
     */
    @RequiresPermissions("pms:key:remove")
    @Log(title = "商品属性名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsAttrKeyService.deletePmsAttrKeyByIds(ids));
    }
}
